package com.foreveross.crawl.vo;

import java.util.Date;

import org.apache.commons.beanutils.BeanUtils;

import com.foreveross.crawl.common.core.ChannelInfoEntity;
import com.foreveross.crawl.common.core.ProxyChannelRelateEntity;
import com.foreveross.crawl.common.core.ProxyIpEntity;

/** 
 * @ClassName: ProxyChannelRelateVO 
 * @Description: 渠道及代理IP关联
 * @author luofangyi
 * @date 2014-10-16 下午2:59:42 
 *  
 */ 
public class ProxyChannelRelateVO {

	private Long id;
    private int version;
	private Long channelId;
	private String channelName;
	private String ip;
	private Long successNumber;
	private Long failNumber;
	private Date createDate;
	private Date disableDate;
	private String successRate;//成功率
	
	public ProxyChannelRelateVO() {
		super();
	}
	
	public ProxyChannelRelateVO(Long successNumber, Long failNumber) {
		super();
		this.successNumber = successNumber;
		this.failNumber = failNumber;
	}

	public ProxyChannelRelateVO(Long id, Long channelId, String channelName,
			String ip, Long successNumber, Long failNumber) {
		super();
		this.id = id;
		this.channelId = channelId;
		this.channelName = channelName;
		this.ip = ip;
		this.successNumber = successNumber;
		this.failNumber = failNumber;
	}
	
	public ProxyChannelRelateVO(Long channelId, String channelName, String ip) {
		super();
		this.channelId = channelId;
		this.channelName = channelName;
		this.ip = ip;
	}

	/**
	 * 构造代理IP及渠道关联信息
	 * @param id
	 * @param channelId
	 * @param channelName
	 * @param ip
	 * @param successNumber
	 * @param failNumber
	 * @param createDate
	 */
	public ProxyChannelRelateVO(Long id, Long channelId, String channelName,
			String ip, Long successNumber, Long failNumber, Date createDate, Date disableDate) {
		super();
		this.id = id;
		this.channelId = channelId;
		this.channelName = channelName;
		this.ip = ip;
		this.successNumber = successNumber;
		this.failNumber = failNumber;
		this.createDate = createDate;
		this.disableDate = disableDate;
	}
	public ProxyChannelRelateVO(Long channelId, String channelName,
			String ip, Long successNumber, Long failNumber) {
		super();
		this.channelId = channelId;
		this.channelName = channelName;
		this.ip = ip;
		this.successNumber = successNumber;
		this.failNumber = failNumber;
	}

	/**
	 * 构造代理IP信息
	 * @param id
	 * @param ip
	 * @param createDate
	 */
	public ProxyChannelRelateVO(Long id, String ip, Date createDate) {
		super();
		this.id = id;
		this.ip = ip;
		this.createDate = createDate;
	}
	/**
	 * 构造渠道相关信息
	 * @param id
	 * @param channelId
	 * @param channelName
	 * @param createDate
	 */
	public ProxyChannelRelateVO(Long channelId, String channelName,
			Date createDate, boolean isChannel) {
		super();
		this.channelId = channelId;
		this.channelName = channelName;
		this.createDate = createDate;
	}
	public Long getChannelId() {
		return channelId;
	}
	public void setChannelId(Long channelId) {
		this.channelId = channelId;
	}
	public String getChannelName() {
		return channelName;
	}
	public void setChannelName(String channelName) {
		this.channelName = channelName;
	}
	public String getIp() {
		return ip;
	}
	public void setIp(String ip) {
		this.ip = ip;
	}
	public Long getSuccessNumber() {
		return successNumber;
	}
	public void setSuccessNumber(Long successNumber) {
		this.successNumber = successNumber;
	}
	public Long getFailNumber() {
		return failNumber;
	}
	public void setFailNumber(Long failNumber) {
		this.failNumber = failNumber;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	@Override
	public String toString() {
		return "ProxyChannelRelateVO [id=" + id + ", version=" + version
				+ ", channelId=" + channelId + ", channelName=" + channelName
				+ ", ip=" + ip + ", successNumber=" + successNumber
				+ ", failNumber=" + failNumber + ", createDate=" + createDate
				+ ", disableDate=" + disableDate + ", successRate="
				+ successRate + "]";
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((channelId == null) ? 0 : channelId.hashCode());
		result = prime * result
				+ ((channelName == null) ? 0 : channelName.hashCode());
		result = prime * result
				+ ((createDate == null) ? 0 : createDate.hashCode());
		result = prime * result
				+ ((disableDate == null) ? 0 : disableDate.hashCode());
		result = prime * result
				+ ((failNumber == null) ? 0 : failNumber.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((ip == null) ? 0 : ip.hashCode());
		result = prime * result
				+ ((successNumber == null) ? 0 : successNumber.hashCode());
		result = prime * result
				+ ((successRate == null) ? 0 : successRate.hashCode());
		result = prime * result + version;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProxyChannelRelateVO other = (ProxyChannelRelateVO) obj;
		if (channelId == null) {
			if (other.channelId != null)
				return false;
		} else if (!channelId.equals(other.channelId))
			return false;
		if (channelName == null) {
			if (other.channelName != null)
				return false;
		} else if (!channelName.equals(other.channelName))
			return false;
		if (createDate == null) {
			if (other.createDate != null)
				return false;
		} else if (!createDate.equals(other.createDate))
			return false;
		if (disableDate == null) {
			if (other.disableDate != null)
				return false;
		} else if (!disableDate.equals(other.disableDate))
			return false;
		if (failNumber == null) {
			if (other.failNumber != null)
				return false;
		} else if (!failNumber.equals(other.failNumber))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (ip == null) {
			if (other.ip != null)
				return false;
		} else if (!ip.equals(other.ip))
			return false;
		if (successNumber == null) {
			if (other.successNumber != null)
				return false;
		} else if (!successNumber.equals(other.successNumber))
			return false;
		if (successRate == null) {
			if (other.successRate != null)
				return false;
		} else if (!successRate.equals(other.successRate))
			return false;
		if (version != other.version)
			return false;
		return true;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public int getVersion() {
		return version;
	}
	public void setVersion(int version) {
		this.version = version;
	}
	
	public static ProxyIpEntity voToProxyIp(ProxyChannelRelateVO vo) throws Exception{
		ProxyIpEntity domain = new ProxyIpEntity();
		BeanUtils.copyProperties(domain, vo);
		return domain;
	}
	
	public static ChannelInfoEntity voToChannelInfo(ProxyChannelRelateVO vo) throws Exception{
		ChannelInfoEntity domain = new ChannelInfoEntity();
		BeanUtils.copyProperties(domain, vo);
		return domain;
	}
	
	public static ProxyChannelRelateVO domainToVo(ChannelInfoEntity domain) throws Exception{
		ProxyChannelRelateVO vo = new ProxyChannelRelateVO();
		BeanUtils.copyProperties(vo, domain);
		return vo;
	}
	
	public static ProxyChannelRelateEntity voToProxyChannelRelate(ProxyChannelRelateVO vo) throws Exception{
		ProxyChannelRelateEntity domain = new ProxyChannelRelateEntity();
		BeanUtils.copyProperties(domain, vo);
		domain.setProxyIp(ProxyIpEntity.findProxyIpByIp(vo.getIp()));
		domain.setChannelInfo(ChannelInfoEntity.findChannelInfoByChannelId(vo.getChannelId()));
		return domain;
	}
	
	public static ProxyChannelRelateVO domainToVo(ProxyIpEntity domain) throws Exception{
		ProxyChannelRelateVO vo = new ProxyChannelRelateVO();
		BeanUtils.copyProperties(vo, domain);
		return vo;
	}
	
	public static ProxyChannelRelateVO domainToVo(ProxyChannelRelateEntity domain) throws Exception{
		ProxyChannelRelateVO vo = new ProxyChannelRelateVO();
		BeanUtils.copyProperties(vo, domain);
		return vo;
	}

	public String getSuccessRate() {
		return successRate;
	}

	public void setSuccessRate(String successRate) {
		this.successRate = successRate;
	}

	public Date getDisableDate() {
		return disableDate;
	}

	public void setDisableDate(Date disableDate) {
		this.disableDate = disableDate;
	}
}
